package br.elsa.survey.view.beans.managed;

import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
import javax.inject.Inject;

import br.elsa.survey.domain.qualifiers.NewEntity;
import br.elsa.survey.domain.questions.DiscursiveQuestion;
import br.elsa.survey.domain.questions.QuestionsFactory;
import br.elsa.survey.services.QuestionService;
import br.elsa.survey.view.messages.ViewMessages;

/**
 * Component that handles all event from the view
 * /views/questions/discursive/createForm.xhtml
 * 
 * <p>
 * This component delegates to the business logic service
 * {@link QuestionService} the responsibility of create a new
 * {@link DiscursiveQuestion} into the database.
 * </p>
 * 
 * @author diego
 * @since 2010-10-03
 */
@ManagedBean
@RequestScoped
public class DiscursiveQuestionCreationView extends AbstractQuestionCreationView {

	/**
	 * Injects a new instance of {@link DiscursiveQuestion}, created by
	 * {@link QuestionsFactory}.
	 */
	@Inject
	@NewEntity
	private DiscursiveQuestion newQuestion;

	/**
	 * Default constructor used by CDI mechanisms to create a new instance of
	 * this class.
	 * 
	 * TODO: It is possible to inject dependencies using class constructor,
	 * <b>BUT</b>, for some reson, it is not working. I get the message that
	 * this normal scoped component is not proxyable! WTF?!
	 */
	public DiscursiveQuestionCreationView() {
	}

	/**
	 * Constructor used by Test Classes to inject Mock dependencies.
	 * 
	 * @param questionService
	 *            mock dependency
	 * @param newQuestion
	 *            mock dependency
	 */
	public DiscursiveQuestionCreationView(DiscursiveQuestion newQuestion, QuestionsFactory questionsFactory, QuestionService questionService, ViewMessages viewMessages) {

		super(questionsFactory, questionService, viewMessages);
		this.newQuestion = newQuestion;
	}

	public void resetViewState() {
		this.newQuestion = questionsFactory.createDiscursiveQuestion();
	}

	public DiscursiveQuestion getNewQuestion() {
		return newQuestion;
	}

}
